package com.tonann.app.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tonann.common.annotation.Log;
import com.tonann.common.core.controller.BaseController;
import com.tonann.common.core.domain.AjaxResult;
import com.tonann.common.enums.BusinessType;
import com.tonann.app.domain.AppFaultGateway;
import com.tonann.app.service.IAppFaultGatewayService;
import com.tonann.common.utils.poi.ExcelUtil;
import com.tonann.common.core.page.TableDataInfo;

/**
 * 网关故障Controller
 * 
 * @author tonann
 * @date 2022-10-15
 */
@RestController
@RequestMapping("/app/faultGateway")
public class AppFaultGatewayController extends BaseController
{
    @Autowired
    private IAppFaultGatewayService appFaultGatewayService;

    /**
     * 查询网关故障列表
     */
    @PreAuthorize("@ss.hasPermi('app:faultGateway:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppFaultGateway appFaultGateway)
    {
        startPage();
        List<AppFaultGateway> list = appFaultGatewayService.selectAppFaultGatewayList(appFaultGateway);
        return getDataTable(list);
    }

    /**
     * 导出网关故障列表
     */
    @PreAuthorize("@ss.hasPermi('app:faultGateway:export')")
    @Log(title = "网关故障", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppFaultGateway appFaultGateway)
    {
        List<AppFaultGateway> list = appFaultGatewayService.selectAppFaultGatewayList(appFaultGateway);
        ExcelUtil<AppFaultGateway> util = new ExcelUtil<AppFaultGateway>(AppFaultGateway.class);
        util.exportExcel(response, list, "网关故障数据");
    }

    /**
     * 获取网关故障详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:faultGateway:query')")
    @GetMapping(value = "/{faultId}")
    public AjaxResult getInfo(@PathVariable("faultId") Long faultId)
    {
        return AjaxResult.success(appFaultGatewayService.selectAppFaultGatewayByFaultId(faultId));
    }

    /**
     * 新增网关故障
     */
    @PreAuthorize("@ss.hasPermi('app:faultGateway:add')")
    @Log(title = "网关故障", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppFaultGateway appFaultGateway)
    {
        return toAjax(appFaultGatewayService.insertAppFaultGateway(appFaultGateway));
    }

    /**
     * 修改网关故障
     */
    @PreAuthorize("@ss.hasPermi('app:faultGateway:edit')")
    @Log(title = "网关故障", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppFaultGateway appFaultGateway)
    {
        return toAjax(appFaultGatewayService.updateAppFaultGateway(appFaultGateway));
    }

    /**
     * 删除网关故障
     */
    @PreAuthorize("@ss.hasPermi('app:faultGateway:remove')")
    @Log(title = "网关故障", businessType = BusinessType.DELETE)
	@DeleteMapping("/{faultIds}")
    public AjaxResult remove(@PathVariable Long[] faultIds)
    {
        return toAjax(appFaultGatewayService.deleteAppFaultGatewayByFaultIds(faultIds));
    }
}
